//
//  TCell.swift
//  AliBaiChuan
//
//  Created by 郑东喜 on 2017/2/21.
//  Copyright © 2017年 郑东喜. All rights reserved.
//

import UIKit

protocol TCellDelagate {
    func getText(str : String,cellIndex index : NSIndexPath)
}


class TCell: UITableViewCell {
    //代理
    static let shared = TCell()
    
    var delegate : TCellDelagate?
    
    var index : NSIndexPath?
    
    //间距
    let margin : CGFloat = 10
    
    //图片
    lazy var imgView: UIImageView = {
        let i : UIImageView = UIImageView.init(frame: CGRect.init(x: SW * 0.75, y: self.margin, width: 30, height: 30))
        i.image = UIImage.init(named: "bgView")
        i.backgroundColor = .gray
        return i
    }()
    
    lazy var textTF: UITextField = {
        let tf : UITextField = UITextField.init(frame: CGRect.init(x: self.margin, y: self.margin, width: SW - 2 * self.margin, height: 2 * self.margin))
        tf.placeholder = "测试"
        tf.delegate = self
        return tf
    }()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        addSubview(imgView)
        addSubview(textTF)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


extension TCell : UITextFieldDelegate {
    func textFieldDidEndEditing(_ textField: UITextField) {
        self.delegate?.getText(str: textField.text!, cellIndex: index!)
    }
}
